<?php
	include("includes/secure.php");
	include("includes/config.php");
	include("includes/class/cliente_pila.class.php");
	require_once("includes/class/employed.class.php");	
	
	$cliente_pila = new Cliente_pila(); 
	$employed1 =  new Employed();	
	$company =  $cliente_pila->companyList();
	$employed = $cliente_pila->empleadoList();
	$parameter = $cliente_pila->parameterList();
	$dateValue = date("d/m/Y");
	
	$eps_code = $hdv_code  = 0;
		
	$employed2 		= $cliente_pila->listEmployedSelect();
	$employed_ced   = $cliente_pila->listEmployedCedSelect();
	$where_employed = "";
	
	$employed3			= '';
	$employed4			= '';
	
	$getNumber = $cliente_pila->getNumberReceipt();

	$getNumber= $getNumber+1;
	$cli_code = 0;
	$clip_receipt = cerosIzquierda($getNumber);	

	$msg_info = $msg_alert = $msg_error = false;
	$_SESSION['msg_cool'] = '';
	$show_msg = 0;
			
	if(isset($_POST['addClientePila']) && $_POST['addClientePila'] == 1){
		$action = $_POST["action"];
		$numero = $_POST['input_eps']; 
		$data->clip_letras = num2letras($numero);
		$data->clip_receipt = $clip_receipt;
		$data->clip_date_periodo = cambiarFormatoFecha($dateValue,2);
		$data->clip_periodo = cambiarFormatoFecha($_POST['clip_periodo'],7);
		$data->hdvc_code = trim(mysql_real_escape_string($_POST['hdvc_code']));
		$data->hdv_code = trim(mysql_real_escape_string($_POST['clip_employed_code']));
		$data->clip_company_name = trim(mysql_real_escape_string($_POST['clip_company_name']));
		$data->clip_company_nit = trim(mysql_real_escape_string($_POST['clip_company_nit']));
		$data->clip_company_address = trim(mysql_real_escape_string($_POST['clip_company_address']));
		$data->clip_employed_name = trim(mysql_real_escape_string($_POST['clip_employed_name']));
		$data->clip_employed_lastname = trim(mysql_real_escape_string($_POST['clip_employed_lastname']));
		$data->clip_employed_cedula = trim(mysql_real_escape_string($_POST['clip_employed_cedula']));
		$data->clip_employed_address = trim(mysql_real_escape_string($_POST['clip_employed_address']));
		$data->clip_reingreso = trim(mysql_real_escape_string($_POST['clip_reingreso']));
		$data->clip_otros = trim(mysql_real_escape_string($_POST['clip_otros']));
		$data->clip_ajuste  = trim(mysql_real_escape_string($_POST['clip_ajuste']));
		$data->clip_admin = $_POST["clip_admin"];
		$data->clip_admin_iva = $_POST["clip_admin_iva"];
		$data->clip_value_admission = $_POST["clip_value_admission"];
		$data->clip_funeral = $_POST["clip_funeral"];
		$data->clip_name_eps = $_POST["clip_name_eps"];
		$data->clip_value_eps = $_POST["clip_value_eps"];
		$data->clip_name_arp = $_POST["clip_name_arp"];
		$data->clip_value_arp = $_POST["clip_value_arp"];
		$data->clip_name_afp = $_POST["clip_name_afp"];
		$data->clip_value_afp = $_POST["clip_value_afp"];
		$data->clip_name_parafiscal  = $_POST["clip_name_parafiscal"];
		$data->clip_value_parafiscal  = $_POST["clip_value_parafiscal"];
		$data->clip_name_poliza = $_POST["clip_name_poliza"];
		$data->clip_value_poliza = $_POST["clip_value_poliza"];
		$data->clip_name_seguro_vida = $_POST["clip_name_seguro_vida"];
		$data->clip_value_seguro_vida = $_POST["clip_value_seguro_vida"];
		$data->clip_name_otros = $_POST["clip_name_otros"];
		$data->clip_value_otros = $_POST["clip_value_otros"];
		$data->clip_reingreso = $_POST["clip_reingreso"];
		$data->clip_aporte_mutual = $_POST["clip_aporte_mutual"];
		$data->clip_otros = $_POST["clip_otros"];
		$data->clip_ajuste = $_POST["clip_ajuste"];
		$data->clip_interes_mora = $_POST["clip_interes_mora"];
		$data->clip_descuentos = $_POST["clip_descuentos"];
		$data->clip_recibido = $_SESSION['use_name'].' '.$_SESSION['use_lastname'];
		$data->clip_total = trim(mysql_real_escape_string($_POST['input_eps']));
		
		if ($cliente_pila->addClientePila($data)){
			$msg_info = true;
				$_SESSION["msg_cool"] .= 'Se adiciono el recibo satisfactoriamente..!!!<br />';
			echo "<script> window.location.href='listClientePila.php?show_msg=2'</script>";
		}
		else{
			$msg_error = true;
				$_SESSION["msg_cool"] .= 'No pudo ser adicionado el recibo... Sorry..!!!<br />';
			echo "<script> window.location.href='listClientePila.php?show_msg=1'</script>";
		}
	}
	
	if ( $msg_error )
		$show_msg = 1;
	elseif ( $msg_alert )
		$show_msg = 2;
	elseif ( $msg_info )
		$show_msg = 3;	
		

?>